package com.spider.controller;

import com.spider.entites.User;
import com.spider.service.UserService;
import com.spider.utils.JwtUtils;
import com.spider.vo.ResultVo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 登录接口
 * @author panglin
 * @date 2020/11/19 10:40
 */
@RestController
@RequestMapping("api")
public class LoginController {
    
    @Resource
    private UserService userService;

    @PostMapping("login")
    public ResultVo login(@RequestBody User user){
        User info = this.userService.getUser(user);
        if (info==null){
            return ResultVo.builder(403, "未授权用户");
        }else {
            return ResultVo.builder(200, JwtUtils.token(info));
        }
    }
}
